// 添加相关操作说明 20210929 耿琰
// 修改相关操作说明 20211009 耿琰
// ===================================================================== antd
import { Menu } from 'antd'
// ===================================================================== Declare
const { $fn, $http, $Lazy } = window
// ===================================================================== Lazy
const confirm 				= $Lazy.file(()=>import('./confirm')) 
const PreviewAuditReport 	= $Lazy.file(()=>import('@views/_public/preview-audit-report/js/utils'))
const Export 				= $Lazy.file(()=>import('#private/common/export'))
// ===================================================================== 操作按钮
const Index =  function({ selectedKeys, selectedRows, data, pagingLoading, query, mode }){
	// const { info } = this.state
	const disabled = !$fn.hasArray(selectedKeys) || pagingLoading
	const resultDisabled = !$fn.hasArray(data) || pagingLoading
	const param = { selectedKeys, selectedRows, data, query  }
	const rows = $fn.hasArray(selectedRows) ? selectedRows[selectedRows.length - 1] : {}
	const _confirm = name => {
		return { 
			name, 
			tipName:name === '保存结果' ? 'SaveResultBtn' : 
				(name === '提交' ? 'PresentBtn' : 
				(name === '迟发' ? 'TardyBtn' : 
				(name === '退单' ? 'ChargebackBtn' :
				(name === '删除结果' ? 'DeleteResultBtn' : 
				(name === '项目终止' ? 'TerminationBtn' : 
				(name === '批量批准' ? 'BatchApprovalBtn' : 
				(name === '手动批准' ? 'HandAuditBtn' : ''))))))),
			disabled:name === '保存结果' ? resultDisabled : disabled , 
			onClick: ()=> confirm.then(f=>f.call(this,name, param)) 
		}
	}
	const btnData = [{value:1,name:'上机'},{value:2,name:'全部空结果上机'},{value:3,name:'选择性空结果上机'}]
	const onClickBtn = ({value,name}) => {
		const param = {selectedKeys:selectedKeys || [], selectedRows: selectedRows || [], data:data||[], query:this.props.top.query}
		if(name !== '上机'){		// 空结果上机
			let btnLen
			const is_null = name === '全部空结果上机'? 1 : 2
			const spec_codes = selectedRows?.map(v => v.spec_code)
			let params = { ids: selectedKeys || [], ...this.props.top.query, spec_codes:spec_codes || [], commit_type: this.rowsType }
			if(!this.isBingLiMode){
				params = { ...params, cross_page_submit:this.cross_page_submit||0 }
			}
			$http.submit(null,'ts-report-card/getCountByNull',{ param:{...params,is_null} }).then(data=>{
				btnLen = data[0]
				confirm.then(f=>f.call(this,name, {...param, btnLen} ))
			})
		}else{						// 上机
			confirm.then(f=>f.call(this,name, param))
		}
	}
	const menu = (
		<Menu>
			{btnData.map((v,i)=>(
				<Menu.Item key={i}>
					<div onClick={() => onClickBtn(v)}>{v.name}</div>
				</Menu.Item>
			))}
		</Menu>
	)
	return {
		// 上机、保存结果、提交、删除结果、迟发、退单、项目终止、批量批准、手动批准
		confirm:_confirm,
		// 上机增加空结果上机 2021-9-28  --马婷
		// 上机
		operateComputer: { tipName:'EmbarkationBtn', disabled: resultDisabled, type: 'select', menu},
		// 不通过/拒绝
		noPass: (title,name) =>  ({ name:title, tipName:name === '不通过' ? 'NoPassBtn' : 'RefuseBtn', disabled, onClick: ()=> this.noPassModal.open(title, {query, selectedKeys, selectedRows}) }),
		// 手动批准,
		handAudit: (title = '手动批准') => {
			const { is_same_lab } = rows || {}
			if(+is_same_lab === 1 && selectedKeys.length === 1){
				return { name:title, tipName:'HandAuditBtn', disabled, onClick: ()=> this.handAuditModal.open(title,{query, rows, use_old_approve_at: this.use_old_approve_at}) }
			}else{
				return _confirm(title)
			}
		},
		// 合并项目
		// 添加相关操作说明 20210927 耿琰
		mergeProject: title =>  ({ name:title, tipName:'merge', disabled, onClick: ()=> this.mergeProjectModal.open(title, {query, rows}) }),
		// 合并项目管理
		mergeProjectManage: title => {
			return { name:title, tipName:'MergeProjectManageBtn', disabled:pagingLoading, onClick: ()=> $fn.pushTo(this,`merge-project-list`) }
		},
		// 预览并批准报告单
		previewAndAudit: title => {
			return { name:title, tipName:'PreviewAndAuditBtn', disabled, onClick: ()=> {
				const { result_model, project_id } =  $fn.getCenterQuery()
				if($fn.hasObject(this.info)){
					const { spec_num, spec_code, uuid } = this.info
					PreviewAuditReport.then(f => f.call(this,{ spec_num, spec_code, uuid, project_id, result_model, test_model: true }))
				}else{
					$fn.toast('请选择一条数据')
				}
			} }
		},
		// 预览报告单
		perviewReport: { name:'预览报告单', tipName:'PerviewReportBtn', disabled: !$fn.hasObject(this.info),  onClick: ()=> {
			if($fn.hasObject(this.info)){
				const { spec_num, spec_code } = this.info
				$fn.pushTo(this,`preview-report?spec_num=${spec_num}&spec_code=${spec_code}`)
			}else{
				$fn.toast('请选择一条数据')
			}
		} },
		// 修改资料
		modInfo: title => ({ name:title, tipName:'ModifiedBtn', disabled, onClick: () => this.patientDetailModal.open(rows['spec_code']) }),
		// 转外包
		waibao: title => ({ name:title, tipName:'OutsourcingBtn', disabled, onClick: () => this.waibaolModal.open({...query, commit_type: this.rowsType}, selectedRows) }),
		// 结果操作日志
		// 添加相关操作说明 20210929 耿琰 20211009 修改
		resultLog: title => ({ name:title, tipName:'resultBtn', disabled, onClick: () => this.controlLogModal.open(rows['uuid']) }),
		// 设置结果
		setResult: title => ({ name:title, disabled, onClick: () => this.setResultModal.open(rows, this.rows) }),
		// 上传结果
		uploadResult: title => ({ name:title, disabled:pagingLoading, onClick: () => {
			const { props:{ top: {query}} } = this
			this.uploadResultModalModal.open(query)
		} }),
		// 危机值报告
		crisisReport: title => ({ name:title, disabled, onClick: () => {} }),
		// 统计 
		statistics: title => ({ name:title, disabled:pagingLoading, onClick: () => { this.statisticsModal.open(mode) } }),
		// 查看同名
		// 添加相关操作说明 20210927 耿琰 	// 新增岗位ID参数 20211020 耿琰
		sameName: title => ({ name:title, tipName:'SameBtn', disabled, onClick: () => { this.checkSameNameModal.open(rows,query.project_id) } }),
		// 终止报告单
		stopReport: title => ({ name:title, tipName:'StopReportBtn', disabled, onClick: () => {
			const { result_id, project_id, status, check_view_mode, result_model} = query
			const param = this.isBingLiMode ? { operation_source:4  } : {}
			if (check_view_mode && this.rowsType === 1) {
				param['check_view_mode'] = 1
				param['commit_type'] = this.rowsType
				param['spec_codes'] = selectedRows.map(v => v.spec_code)
				param['result_model'] = result_model
			}
			this.stopReportModal.open({
				result_id,project_id,status,
				ids:selectedKeys, 
				operation_source:4,
				status_abnormal:45009,
				cross_page_submit:this.cross_page_submit,
				type:'',
				...param
			}) 
		}}),
		// 查看所有、查看待接种、查看收获
		search44015: (title, index) => ({ name:title, disabled:pagingLoading, onClick: () => {
			const arr = ['', 'FL104210000','FL104210001']
			this.onSearch({operation_44015: arr[index]})
		} }),
		// 查看所有、查看待接种、查看收获
		search44018: (title, index) => ({ name:title, disabled:pagingLoading, onClick: () => {
			const arr = ['', 'FL1000010000','FL1000010001','FL1000010002']
			this.onSearch({ operation_44018: arr[index] })
		} }),
		//集团内转外包 2021-7-15 5:49:46 ?F10: PM? --伍智睿
		groupWaibao: title => ({ name:title, onClick: () => this.groupWaibaoModal.open(selectedKeys) }),
		// 修改标本类型
		modSpecType: title => ({ name:title, tipName:'BulkEditingBtn',  disabled, onClick: ()=>this.modSpecTypeModal.open({...query, uuid: selectedKeys, commit_type: this.rowsType}) }),
		// 超级搜索
		superSearch: title => ({ name:title, disabled:pagingLoading, onClick: () => this.superSearchModal.open(this.props.searchRef) }),
		// 导出  2022-7-25 --马婷
		exportList:title => ({ name:title, disabled:pagingLoading, onClick: () => {
			const { props:{ top: {query,searchRef:{model}}} } = this
			const exportParam = {...query,...model}
			Export.then(f=>f.call(this, 'ts-report-card/index', {type:'get',param:exportParam}))
		} }),
		// 生成布板  2022-7-27 --马婷
		createBoard: title => ({ name:title, disabled, onClick: () => this.createBoardModal.open(selectedKeys) }),
	}
}
export default Index